home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
OS
/
ZScrap.cpp
< prev
next >
Wrap
Text File
|
1997-06-18
|
3KB
|
126 lines
/*
* File: ZScrap.cpp
* Summary: Some global functions that make it easier to deal with the Scrap Manager.
* Written by: Jesse Jones
*
* Copyright ゥ 1996 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 7/22/96 JDJ Created.
*/
#include <ZScrap.h>
#include <Scrap.h>
#include <ZExceptions.h>
#include <ZLocker.h>
//---------------------------------------------------------------
//
// InScrap
//
//---------------------------------------------------------------
bool InScrap(OSType type)
{
long offset;
long length = GetScrap(nil, type, &offset);
return length > 0;
}
//---------------------------------------------------------------
//
// GetScrap (OSType)
//
//---------------------------------------------------------------
THandle GetScrap(OSType type)
{
THandle data;
long offset;
OSErr length = (OSErr) GetScrap(data, type, &offset);
if (length < 0)
ThrowOSErr(length);
return data;
}
//---------------------------------------------------------------
//
// PutScrap
//
//---------------------------------------------------------------
void PutScrap(OSType type, const THandle& data)
{
{
TLocker lock(data);
OSErr err = (OSErr) ::PutScrap((long) data.GetSize(), type, (Ptr) data.GetPtr());
ThrowIfOSErr(err);
}
}
//---------------------------------------------------------------
//
// GetScrap ()
//
//---------------------------------------------------------------
THandle GetScrap()
{
THandle data;
// Make sure the scrap data is in memory.
long err = LoadScrap();
if (err == noErr) {
// Get a pointer to the scrap info record.
ScrapStuff* scrap = InfoScrap();
if (scrap->scrapSize > 0) {
// Make a copy of the scrap handle.
Handle temp = scrap->scrapHandle;
OSErr err = HandToHand(&temp);
if (err == noErr) {
// Resize our copy so that it matches the scrapSize.
SetHandleSize(temp, scrap->scrapSize);
if (MemError() == noErr)
data = temp; // THandle will take mac handle
else
DisposeHandle(data);
}
}
}
return data;
}
//---------------------------------------------------------------
//
// SetScrap
//
//---------------------------------------------------------------
void SetScrap(const THandle& oldScrap)
{
if (oldScrap.GetSize() > 0) {
::ZeroScrap();
Handle temp = oldScrap;
OSErr err = HandToHand(&temp);
if (err == noErr) {
ScrapStuff* scrap = InfoScrap();
scrap->scrapHandle = temp;
scrap->scrapSize = GetHandleSize(temp);
}
}
}